package com.gydz.gydzbaseframeworkboot.Common.utils.export;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFComment;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;

public class ExcelUtil {
    //excel默认宽度；
    private static int width = 256*14;
    //默认字体
    private static String excelfont = "微软雅黑";

    public static void main(String[] args) {
        int sheetSize = (int)Math.ceil(new Double(109611)/65535D);System.out.println("sheetSize:"+sheetSize);
    }

    /**
     *
     * @param excelName  导出的EXCEL名字
     * @param sheetName  导出的SHEET名字  当前sheet数目只为1
     * @param headers      导出的表格的表头
     * @param ds_titles      导出的数据 map.get(key) 对应的 key
     * @param ds_format    导出数据的样式
     *                          1:String left;
     *							2:String center
     *							3:String right
     *							4 int  right
     *							5:float ###,###.## right
     *							6:number: #.00% 百分比 right
     * @param widths      表格的列宽度  默认为 256*14
     * @param data        数据集  List<Map>
     * @param response
     * @throws IOException
     */
    public static void export(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
//            fileName = excelName+"_"+dataFmt;
            fileName = excelName;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);

        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                //垂直居中
                style.setVerticalAlignment(style.getVerticalAlignmentEnum().CENTER);
                style.setVerticalAlignment(VerticalAlignment.CENTER);
                style.setAlignment(HorizontalAlignment.CENTER);
                style.setBorderBottom(BorderStyle.THIN);//下边框
                style.setBorderLeft(BorderStyle.THIN);//左边框
                style.setBorderTop(BorderStyle.THIN);//上边框
                style.setBorderRight(BorderStyle.THIN);//右边框
                for (int i = 0; i < headers.length; i++) {
                    sheet.setColumnWidth((short)i,(short)widths[i]);
                    HSSFCell cell = row.createCell(i);
                    cell.setCellValue(headers[i]);
                    cell.setCellStyle(style);
                }
                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setVerticalAlignment(style.getVerticalAlignmentEnum().CENTER);
                    style.setVerticalAlignment(VerticalAlignment.CENTER);
                    style.setAlignment(HorizontalAlignment.CENTER);
                    style.setBorderBottom(BorderStyle.THIN);//下边框
                    style.setBorderLeft(BorderStyle.THIN);//左边框
                    style.setBorderTop(BorderStyle.THIN);//上边框
                    style.setBorderRight(BorderStyle.THIN);//右边框
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }else if(ds_format[i]==7){
                        style.setWrapText(true); //内容过长自动换行
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
//					row.setHeightInPoints((short)250);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }
    public static void export_gprs(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);

        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setVerticalAlignment(style.getVerticalAlignmentEnum().CENTER);
                style.setVerticalAlignment(VerticalAlignment.CENTER);
                style.setAlignment(HorizontalAlignment.CENTER);
                style.setBorderBottom(BorderStyle.THIN);//下边框
                style.setBorderLeft(BorderStyle.THIN);//左边框
                style.setBorderTop(BorderStyle.THIN);//上边框
                style.setBorderRight(BorderStyle.THIN);//右边框
                for (int i = 0; i < headers.length; i++) {
                    sheet.setColumnWidth((short)i,(short)widths[i]);
                    HSSFCell cell = row.createCell(i);
                    cell.setCellValue(headers[i]);
                    cell.setCellStyle(style);
                }
                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setVerticalAlignment(style.getVerticalAlignmentEnum().CENTER);
                    style.setVerticalAlignment(VerticalAlignment.CENTER);
                    style.setAlignment(HorizontalAlignment.LEFT);
                    style.setBorderBottom(BorderStyle.THIN);//下边框
                    style.setBorderLeft(BorderStyle.THIN);//左边框
                    style.setBorderTop(BorderStyle.THIN);//上边框
                    style.setBorderRight(BorderStyle.THIN);//右边框
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    row.setHeightInPoints((short)250);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void export(String excelName, String sheetName,List<String> headers,List<String> ds_titles,List<Integer> ds_format,List<Integer> widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new ArrayList<Integer>();
            for(String obj :ds_titles){
                widths.add(width);
            }
        }
        if(ds_format==null){
            ds_format = new ArrayList<Integer>();
            for(String obj :ds_titles){
                ds_format.add(1);
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                for (int i = 0; i < headers.size(); i++) {
                    sheet.setColumnWidth((short)i,widths.get(i));
                    HSSFCell cell = row.createCell(i);
                    cell.setCellValue(headers.get(i));
                    cell.setCellStyle(style);
                }
                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.size(); i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format.get(i)==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format.get(i)==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format.get(i)==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format.get(i)==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format.get(i)==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format.get(i)==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.size(); j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles.get(j));
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format.get(j)==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles.get(j)))+"")).longValue());
                        }else if(ds_format.get(j)==5|| ds_format.get(j)==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles.get(j)))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles.get(j))+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void export2(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = excelName;
//    	String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
//		if(StringUtils.isNotEmpty(excelName)){
//			fileName = excelName+"_"+dataFmt;
//		}
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //标题行
            HSSFRow  row0 = sheet.createRow(0);
            row0.setHeight((short) (200*2.6));
            //表头样式
            HSSFCellStyle style0 = wb.createCellStyle();
            HSSFFont font0 = wb.createFont();
            font0.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            font0.setFontName(excelfont);
            font0.setFontHeightInPoints((short) 12);
            style0.setFont(font0);
            style0.setAlignment(HSSFCellStyle.ALIGN_LEFT);
            style0.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            HSSFCell cell0 = row0.createCell(0);
            cell0.setCellValue("                                                                                              "+excelName);
            cell0.setCellStyle(style0);
            CellRangeAddress region = new CellRangeAddress(0, 0, 0, headers.length-1);
            sheet.addMergedRegion(region);
            //创建表头，如果没有跳过
            int headerrow = 1;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                row.setHeight((short) (200*2));
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                for (int i = 0; i < headers.length; i++) {
                    sheet.setColumnWidth((short)i,(short)widths[i]);
                    HSSFCell cell = row.createCell(i);
                    cell.setCellValue(headers[i]);
                    cell.setCellStyle(style);
                }
                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List<HSSFCellStyle> styleList = new ArrayList<HSSFCellStyle>();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        boolean wrapped = (o==null) ? false :StringUtils.contains(o.toString(), "\r\n");
                        HSSFCellStyle style = styleList.get(j);
                        style.setWrapText(wrapped);
                        cell.setCellStyle(style);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(new HSSFRichTextString(map.get(ds_titles[j])+""));
                        }
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void export2(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths,
                               List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response,
                               HashMap<Integer,Boolean> rowMap, HashMap<Integer,ArrayList<Integer>> rcMap) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                for (int i = 0; i < headers.length; i++) {
                    sheet.setColumnWidth((short)i,(short)widths[i]);
                    HSSFCell cell = row.createCell(i);
                    cell.setCellValue(headers[i]);
                    cell.setCellStyle(style);
                }
                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                HSSFCellStyle cellStyle0 = wb.createCellStyle();
                List<HSSFCellStyle> styleList = new ArrayList<HSSFCellStyle>();
                List<HSSFCellStyle> styleList2 = new ArrayList<HSSFCellStyle>();
                List<HSSFCellStyle> styleList3 = new ArrayList<HSSFCellStyle>();
                List<HSSFCellStyle> styleList4 = new ArrayList<HSSFCellStyle>();
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    styleList.add(style);
                }
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//填充单元格
                    style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);//设置单元格背景色
                    styleList2.add(style);
                }
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    font.setColor(HSSFColor.RED.index);//设置字体颜色
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//填充单元格
                    style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);//设置单元格背景色
                    styleList3.add(style);
                }
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    font.setColor(HSSFColor.RED.index);//设置字体颜色
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    styleList4.add(style);
                }
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    boolean highBg = rowMap.get(i+1);
                    List<Integer> redCols = rcMap.get(i+1);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        if(highBg){
                            cell.setCellStyle(styleList2.get(j));
                            if(redCols != null){
                                if(redCols.contains(j)){
                                    cell.setCellStyle(styleList3.get(j));
                                }
                            }
                        }else{
                            cell.setCellStyle(styleList.get(j));
                            if(redCols != null){
                                if(redCols.contains(j)){
                                    cell.setCellStyle(styleList4.get(j));
                                }
                            }
                        }
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void export3(String excelName, String sheetName,String[] headers,String[] headersComment,String[] ds_titles,int[] ds_format,int[] widths,
                               List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response,
                               HashMap<Integer,Boolean> rowMap, HashMap<Integer,ArrayList<Integer>> rcMap) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            HSSFPatriarch p = sheet.createDrawingPatriarch();
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                // 创建绘图对象
                for (int i = 0; i < headers.length; i++) {
                    sheet.setColumnWidth((short)i,(short)widths[i]);
                    HSSFCell cell = row.createCell(i);
                    if(StringUtils.isNotBlank(headersComment[i])){
                        cell.setCellValue(new HSSFRichTextString(headers[i]));
                        // 前四个参数是坐标点,后四个参数是编辑和显示批注时的大小.
                        HSSFComment comment = p.createComment(new HSSFClientAnchor(0, 0, 0,0, (short) 3, 3, (short) 4, 6));
                        // 输入批注信息
                        comment.setString(new HSSFRichTextString(headersComment[i]));
                        // 将批注添加到单元格对象中
                        cell.setCellComment(comment);
                    }else{
                        cell.setCellValue(headers[i]);
                    }
                    cell.setCellStyle(style);
                }
                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                HSSFCellStyle cellStyle0 = wb.createCellStyle();
                List<HSSFCellStyle> styleList = new ArrayList<HSSFCellStyle>();
                List<HSSFCellStyle> styleList2 = new ArrayList<HSSFCellStyle>();
                List<HSSFCellStyle> styleList3 = new ArrayList<HSSFCellStyle>();
                List<HSSFCellStyle> styleList4 = new ArrayList<HSSFCellStyle>();
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    styleList.add(style);
                }
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//填充单元格
                    style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);//设置单元格背景色
                    styleList2.add(style);
                }
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    font.setColor(HSSFColor.RED.index);//设置字体颜色
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//填充单元格
                    style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);//设置单元格背景色
                    styleList3.add(style);
                }
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    font.setColor(HSSFColor.RED.index);//设置字体颜色
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    styleList4.add(style);
                }
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    boolean highBg = rowMap.get(i+1);
                    List<Integer> redCols = rcMap.get(i+1);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        if(highBg){
                            cell.setCellStyle(styleList2.get(j));
                            if(redCols != null){
                                if(redCols.contains(j)){
                                    cell.setCellStyle(styleList3.get(j));
                                }
                            }
                        }else{
                            cell.setCellStyle(styleList.get(j));
                            if(redCols != null){
                                if(redCols.contains(j)){
                                    cell.setCellStyle(styleList4.get(j));
                                }
                            }
                        }
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static HSSFWorkbook exportSheets0(HttpServletRequest request, HttpServletResponse response) throws IOException {
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        return wb;
    }

    public static HSSFWorkbook exportSheets0() throws IOException {
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        return wb;
    }

    public static void exportSheets1(HSSFWorkbook wb,String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths,
                                     List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response,
                                     HashMap<Integer,Boolean> rowMap, HashMap<Integer,ArrayList<Integer>> rcMap) throws IOException {
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        if(sheetSize == 0){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                for (int i = 0; i < headers.length; i++) {
                    sheet.setColumnWidth((short)i,(short)widths[i]);
                    HSSFCell cell = row.createCell(i);
                    cell.setCellValue(headers[i]);
                    cell.setCellStyle(style);
                }
                headerrow++;
            }
        }
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                for (int i = 0; i < headers.length; i++) {
                    sheet.setColumnWidth((short)i,(short)widths[i]);
                    HSSFCell cell = row.createCell(i);
                    cell.setCellValue(headers[i]);
                    cell.setCellStyle(style);
                }
                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                HSSFCellStyle cellStyle0 = wb.createCellStyle();
                List<HSSFCellStyle> styleList = new ArrayList<HSSFCellStyle>();
                List<HSSFCellStyle> styleList2 = new ArrayList<HSSFCellStyle>();
                List<HSSFCellStyle> styleList3 = new ArrayList<HSSFCellStyle>();
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    styleList.add(style);
                }
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//填充单元格
                    style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);//设置单元格背景色
                    styleList2.add(style);
                }
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    font.setColor(HSSFColor.RED.index);//设置字体颜色
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//填充单元格
                    style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);//设置单元格背景色
                    styleList3.add(style);
                }
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    boolean highBg = rowMap.get(i+1);
                    List<Integer> redCols = rcMap.get(i+1);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        if(highBg){
                            cell.setCellStyle(styleList2.get(j));
                            if(redCols != null){
                                if(redCols.contains(j)){
                                    cell.setCellStyle(styleList3.get(j));
                                }
                            }
                        }else{
                            cell.setCellStyle(styleList.get(j));
                        }
                    }
                    headerrow++;
                }
            }
        }

    }

    public static void exportSheets1(HSSFWorkbook wb,String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths,
                                     List<Map<String,Object>> data ,HashMap<Integer,Boolean> rowMap, HashMap<Integer,ArrayList<Integer>> rcMap) throws IOException {
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        if(sheetSize == 0){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                for (int i = 0; i < headers.length; i++) {
                    sheet.setColumnWidth((short)i,(short)widths[i]);
                    HSSFCell cell = row.createCell(i);
                    cell.setCellValue(headers[i]);
                    cell.setCellStyle(style);
                }
                headerrow++;
            }
        }
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                for (int i = 0; i < headers.length; i++) {
                    sheet.setColumnWidth((short)i,(short)widths[i]);
                    HSSFCell cell = row.createCell(i);
                    cell.setCellValue(headers[i]);
                    cell.setCellStyle(style);
                }
                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                HSSFCellStyle cellStyle0 = wb.createCellStyle();
                List<HSSFCellStyle> styleList = new ArrayList<HSSFCellStyle>();
                List<HSSFCellStyle> styleList2 = new ArrayList<HSSFCellStyle>();
                List<HSSFCellStyle> styleList3 = new ArrayList<HSSFCellStyle>();
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    styleList.add(style);
                }
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//填充单元格
                    style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);//设置单元格背景色
                    styleList2.add(style);
                }
                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    font.setColor(HSSFColor.RED.index);//设置字体颜色
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }

                    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//填充单元格
                    style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);//设置单元格背景色
                    styleList3.add(style);
                }
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    boolean highBg = (rowMap != null && rowMap.size() > 1) ? rowMap.get(i+1) : false;
                    List<Integer> redCols = (rcMap != null && rcMap.size() > 1) ? rcMap.get(i+1) : null;
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        if(highBg){
                            cell.setCellStyle(styleList2.get(j));
                            if(redCols != null){
                                if(redCols.contains(j)){
                                    cell.setCellStyle(styleList3.get(j));
                                }
                            }
                        }else{
                            cell.setCellStyle(styleList.get(j));
                        }
                    }
                    headerrow++;
                }
            }
        }

    }

    public static void exportSheets2(HSSFWorkbook wb,String excelName,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);

        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportSheets2(String filepath,HSSFWorkbook wb,String excelName) throws IOException {
        //设置文件名
        String fileName = excelName+".xls";
        //判断文件是否已存在，若存在先删除
        deleteIfExists(new File(filepath+fileName));
        //判断是否存在目录. 不存在则创建
        isChartPathExist(filepath);
        //输出Excel文件1
        FileOutputStream output=new FileOutputStream(filepath+fileName);
        wb.write(output);//写入磁盘
        output.close();

    }

    /**
     * 判断文件夹是否存在，如果不存在则新建
     *
     * @param dirPath 文件夹路径
     */
    private static void isChartPathExist(String dirPath) {
        File file = new File(dirPath);
        if (!file.exists()) {
            file.mkdirs();
        }
    }
    /**
     * 删除文件或文件夹
     */
    public static void deleteIfExists(File file) throws IOException {
        if (file.exists()) {
            if (file.isFile()) {
                if (!file.delete()) {
                    throw new IOException("Delete file failure,path:" + file.getAbsolutePath());
                }
            }
        }
    }

    public static void exportTemplate(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = 1;
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                for (int i = 0; i < headers.length; i++) {
                    sheet.setColumnWidth((short)i,(short)widths[i]);
                    HSSFCell cell = row.createCell(i);
                    cell.setCellValue(headers[i]);
                    cell.setCellStyle(style);
                }
                headerrow++;
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }


    public static void exportTemplateDb10(String excelName, String sheetName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = 1;
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            HSSFRow  row = sheet.createRow(headerrow);
            //表头样式
            HSSFCellStyle style = wb.createCellStyle();
            HSSFFont font = wb.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            font.setFontName(excelfont);
            font.setFontHeightInPoints((short) 11);
            style.setFont(font);
            style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            style.setBorderRight(HSSFCellStyle.BORDER_THIN);
            style.setBorderTop(HSSFCellStyle.BORDER_THIN);

            sheet.setColumnWidth(0,256*14);
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("序号");
            cell.setCellStyle(style);
            CellRangeAddress region = new CellRangeAddress(0, 2, 0, 0);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(1,256*19);
            cell = row.createCell(1);
            cell.setCellValue("路局名称");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 2, 1, 1);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(2,256*19);
            cell = row.createCell(2);
            cell.setCellValue("线路名称");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 2, 2, 2);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(3,256*19);
            cell = row.createCell(3);
            cell.setCellValue("小区名称");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 2, 3, 3);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(4,256*19*4);
            cell = row.createCell(4);
            cell.setCellValue("频率分配");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 4, 7);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(8,256*19*2);
            cell = row.createCell(8);
            cell.setCellValue("小区选择参数");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 8, 9);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(10,256*19*9);
            cell = row.createCell(10);
            cell.setCellValue("切换参数");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 10, 18);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(19,256*14*5);
            cell = row.createCell(19);
            cell.setCellValue("定时器参数");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 19, 23);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(24,256*19);
            cell = row.createCell(24);
            cell.setCellValue("无线链路超时（秒）");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 2, 24, 24);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(25,256*14);
            cell = row.createCell(25);
            cell.setCellValue("备注");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 2, 25, 25);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            HSSFRow  row2 = sheet.getRow(1);
            if(row2==null){
                row2 = sheet.createRow(1);
            }
            sheet.setColumnWidth(4,256*19);
            cell = row2.createCell(4);
            cell.setCellValue("AFC1");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 2, 4, 4);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(5,256*19);
            cell = row2.createCell(5);
            cell.setCellValue("AFC2");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 2, 5, 5);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(6,256*19);
            cell = row2.createCell(6);
            cell.setCellValue("AFC3");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 2, 6, 6);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(7,256*19);
            cell = row2.createCell(7);
            cell.setCellValue("AFC4");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 2, 7, 7);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(8,256*19);
            cell = row2.createCell(8);
            cell.setCellValue("移动台允许接入的最小接收电平(dBm）");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 2, 8, 8);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(9,256*19);
            cell = row2.createCell(9);
            cell.setCellValue("小区重选偏置(步长)");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 2, 9, 9);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(10,256*14*2);
            cell = row2.createCell(10);
            cell.setCellValue("质量切换");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 1, 10, 11);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(11,256*19*2);
            cell = row2.createCell(12);
            cell.setCellValue("电平切换");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 1, 12, 13);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(14,256*19*4);
            cell = row2.createCell(14);
            cell.setCellValue("功率预算性切换");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 1, 14, 17);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(18,256*19);
            cell = row2.createCell(18);
            cell.setCellValue("距离切换");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 1, 18, 18);

            sheet.setColumnWidth(19,256*14);
            cell = row2.createCell(19);
            cell.setCellValue("T3101");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 2, 19, 19);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(20,256*14);
            cell = row2.createCell(20);
            cell.setCellValue("T3103");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 2, 20, 20);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(21,256*14);
            cell = row2.createCell(21);
            cell.setCellValue("T3107");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 2, 21, 21);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(22,256*14);
            cell = row2.createCell(22);
            cell.setCellValue("T3109");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 2, 22, 22);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(23,256*14);
            cell = row2.createCell(23);
            cell.setCellValue("T3122");
            cell.setCellStyle(style);
            region = new CellRangeAddress(1, 2, 23, 23);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);


            HSSFRow  row3 = sheet.getRow(2);
            if(row3==null){
                row3 = sheet.createRow(2);
            }
            sheet.setColumnWidth(10,256*19);
            cell = row3.createCell(10);
            cell.setCellValue("下行质量接收门限");
            cell.setCellStyle(style);
            region = new CellRangeAddress(2, 2, 10, 10);

            sheet.setColumnWidth(11,256*19);
            cell = row3.createCell(11);
            cell.setCellValue("上行质量接收门限");
            cell.setCellStyle(style);
            region = new CellRangeAddress(2, 2, 11, 11);

            sheet.setColumnWidth(12,256*19);
            cell = row3.createCell(12);
            cell.setCellValue("下行链路边缘切换门限(dBm）");
            cell.setCellStyle(style);
            region = new CellRangeAddress(2, 2, 12, 12);

            sheet.setColumnWidth(13,256*19);
            cell = row3.createCell(13);
            cell.setCellValue("上行链路边缘切换门限(dBm）");
            cell.setCellStyle(style);
            region = new CellRangeAddress(2, 2, 13, 13);

            sheet.setColumnWidth(14,256*19);
            cell = row3.createCell(14);
            cell.setCellValue("开关参数");
            cell.setCellStyle(style);
            region = new CellRangeAddress(2, 2, 14, 14);

            sheet.setColumnWidth(15,256*19);
            cell = row3.createCell(15);
            cell.setCellValue("切换容限（dB）");
            cell.setCellStyle(style);
            region = new CellRangeAddress(2, 2, 15, 15);

            sheet.setColumnWidth(16,256*19);
            cell = row3.createCell(16);
            cell.setCellValue("乒乓切换保护时间");
            cell.setCellStyle(style);
            region = new CellRangeAddress(2, 2, 16, 16);

            sheet.setColumnWidth(17,256*19);
            cell = row3.createCell(17);
            cell.setCellValue("切换判决（次）");
            cell.setCellStyle(style);
            region = new CellRangeAddress(2, 2, 17, 17);

            sheet.setColumnWidth(18,256*19);
            cell = row3.createCell(18);
            cell.setCellValue("距离切换门限");
            cell.setCellStyle(style);
            region = new CellRangeAddress(2, 2, 18, 18);
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportDb10(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);

                sheet.setColumnWidth(0,256*14);
                HSSFCell cell = row.createCell(0);
                cell.setCellValue("序号");
                cell.setCellStyle(style);
                CellRangeAddress region = new CellRangeAddress(0, 2, 0, 0);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(1,256*19);
                cell = row.createCell(1);
                cell.setCellValue("路局名称");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 2, 1, 1);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(2,256*19);
                cell = row.createCell(2);
                cell.setCellValue("线路名称");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 2, 2, 2);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(3,256*19);
                cell = row.createCell(3);
                cell.setCellValue("小区名称");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 2, 3, 3);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(4,256*19*4);
                cell = row.createCell(4);
                cell.setCellValue("频率分配");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 4, 7);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(8,256*19*2);
                cell = row.createCell(8);
                cell.setCellValue("小区选择参数");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 8, 9);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(10,256*19*9);
                cell = row.createCell(10);
                cell.setCellValue("切换参数");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 10, 18);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(19,256*14*5);
                cell = row.createCell(19);
                cell.setCellValue("定时器参数");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 19, 23);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(24,256*19);
                cell = row.createCell(24);
                cell.setCellValue("无线链路超时（秒）");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 2, 24, 24);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(25,256*14);
                cell = row.createCell(25);
                cell.setCellValue("备注");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 2, 25, 25);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                headerrow++;

                HSSFRow  row2 = sheet.getRow(1);
                if(row2==null){
                    row2 = sheet.createRow(1);
                }
                sheet.setColumnWidth(4,256*19);
                cell = row2.createCell(4);
                cell.setCellValue("AFC1");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 2, 4, 4);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(5,256*19);
                cell = row2.createCell(5);
                cell.setCellValue("AFC2");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 2, 5, 5);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(6,256*19);
                cell = row2.createCell(6);
                cell.setCellValue("AFC3");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 2, 6, 6);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(7,256*19);
                cell = row2.createCell(7);
                cell.setCellValue("AFC4");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 2, 7, 7);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(8,256*19);
                cell = row2.createCell(8);
                cell.setCellValue("移动台允许接入的最小接收电平(dBm）");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 2, 8, 8);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(9,256*19);
                cell = row2.createCell(9);
                cell.setCellValue("小区重选偏置(步长)");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 2, 9, 9);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(10,256*19*2);
                cell = row2.createCell(10);
                cell.setCellValue("质量切换");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 1, 10, 11);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(11,256*19*2);
                cell = row2.createCell(12);
                cell.setCellValue("电平切换");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 1, 12, 13);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(14,256*19*4);
                cell = row2.createCell(14);
                cell.setCellValue("功率预算性切换");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 1, 14, 17);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(18,256*14);
                cell = row2.createCell(18);
                cell.setCellValue("距离切换");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 1, 18, 18);

                sheet.setColumnWidth(19,256*14);
                cell = row2.createCell(19);
                cell.setCellValue("T3101");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 2, 19, 19);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(20,256*14);
                cell = row2.createCell(20);
                cell.setCellValue("T3103");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 2, 20, 20);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(21,256*14);
                cell = row2.createCell(21);
                cell.setCellValue("T3107");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 2, 21, 21);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(22,256*14);
                cell = row2.createCell(22);
                cell.setCellValue("T3109");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 2, 22, 22);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(23,256*14);
                cell = row2.createCell(23);
                cell.setCellValue("T3122");
                cell.setCellStyle(style);
                region = new CellRangeAddress(1, 2, 23, 23);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                headerrow++;
                HSSFRow  row3 = sheet.getRow(2);
                if(row3==null){
                    row3 = sheet.createRow(2);
                }
                sheet.setColumnWidth(10,256*19);
                cell = row3.createCell(10);
                cell.setCellValue("下行质量接收门限");
                cell.setCellStyle(style);
                region = new CellRangeAddress(2, 2, 10, 10);

                sheet.setColumnWidth(11,256*19);
                cell = row3.createCell(11);
                cell.setCellValue("上行质量接收门限");
                cell.setCellStyle(style);
                region = new CellRangeAddress(2, 2, 11, 11);

                sheet.setColumnWidth(12,256*19);
                cell = row3.createCell(12);
                cell.setCellValue("下行链路边缘切换门限(dBm）");
                cell.setCellStyle(style);
                region = new CellRangeAddress(2, 2, 12, 12);

                sheet.setColumnWidth(13,256*19);
                cell = row3.createCell(13);
                cell.setCellValue("上行链路边缘切换门限(dBm）");
                cell.setCellStyle(style);
                region = new CellRangeAddress(2, 2, 13, 13);

                sheet.setColumnWidth(14,256*19);
                cell = row3.createCell(14);
                cell.setCellValue("开关参数");
                cell.setCellStyle(style);
                region = new CellRangeAddress(2, 2, 14, 14);

                sheet.setColumnWidth(15,256*19);
                cell = row3.createCell(15);
                cell.setCellValue("切换容限（dB）");
                cell.setCellStyle(style);
                region = new CellRangeAddress(2, 2, 15, 15);

                sheet.setColumnWidth(16,256*19);
                cell = row3.createCell(16);
                cell.setCellValue("乒乓切换保护时间");
                cell.setCellStyle(style);
                region = new CellRangeAddress(2, 2, 16, 16);

                sheet.setColumnWidth(17,256*19);
                cell = row3.createCell(17);
                cell.setCellValue("切换判决（次）");
                cell.setCellStyle(style);
                region = new CellRangeAddress(2, 2, 17, 17);

                sheet.setColumnWidth(18,256*19);
                cell = row3.createCell(18);
                cell.setCellValue("距离切换门限");
                cell.setCellStyle(style);
                region = new CellRangeAddress(2, 2, 18, 18);
                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportTemplateDb1(String excelName, String sheetName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = 1;
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            HSSFRow  row = sheet.createRow(headerrow);
            //表头样式
            HSSFCellStyle style = wb.createCellStyle();
            HSSFFont font = wb.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            font.setFontName(excelfont);
            font.setFontHeightInPoints((short) 11);
            style.setFont(font);
            style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            style.setBorderRight(HSSFCellStyle.BORDER_THIN);
            style.setBorderTop(HSSFCellStyle.BORDER_THIN);

            sheet.setColumnWidth(0,256*14);
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("序号");
            cell.setCellStyle(style);
            CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(1,256*19);
            cell = row.createCell(1);
            cell.setCellValue("基站名称");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 1, 1);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(2,256*19*3);
            cell = row.createCell(2);
            cell.setCellValue("基站铁塔位置");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 2, 4);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(5,256*14);
            cell = row.createCell(5);
            cell.setCellValue("基站站型");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 5, 5);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(6,256*14);
            cell = row.createCell(6);
            cell.setCellValue("小区序号");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 6, 6);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(7,256*19);
            cell = row.createCell(7);
            cell.setCellValue("小区名称");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 7, 7);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(8,256*22);
            cell = row.createCell(8);
            cell.setCellValue("全球小区识别码(CGI)");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 8, 8);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(9,256*14);
            cell = row.createCell(9);
            cell.setCellValue("DA值");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 9, 9);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(10,256*19);
            cell = row.createCell(10);
            cell.setCellValue("路由区编码(RAC)");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 10, 10);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(11,256*22);
            cell = row.createCell(11);
            cell.setCellValue("基站识别色码(BSIC)");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 11, 11);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(12,256*14);
            cell = row.createCell(12);
            cell.setCellValue("载频数");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 12, 12);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(13,256*14);
            cell = row.createCell(13);
            cell.setCellValue("归属BSC");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 13, 13);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(14,256*14);
            cell = row.createCell(14);
            cell.setCellValue("基站组环");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 14, 14);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(15,256*14);
            cell = row.createCell(15);
            cell.setCellValue("车站名称");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 15, 15);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(16,256*14);
            cell = row.createCell(16);
            cell.setCellValue("备注");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 16, 16);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(17,256*14);
            cell = row.createCell(17);
            cell.setCellValue("制作要求");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 17, 17);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            HSSFRow  row2 = sheet.getRow(1);
            if(row2==null){
                row2 = sheet.createRow(1);
            }
            sheet.setColumnWidth(2,256*19);
            cell = row2.createCell(2);
            cell.setCellValue("公里标");
            cell.setCellStyle(style);

            sheet.setColumnWidth(3,256*19);
            cell = row2.createCell(3);
            cell.setCellValue("经度");
            cell.setCellStyle(style);

            sheet.setColumnWidth(4,256*19);
            cell = row2.createCell(4);
            cell.setCellValue("纬度");
            cell.setCellStyle(style);
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportDb1(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);

                sheet.setColumnWidth(0,256*14);
                HSSFCell cell = row.createCell(0);
                cell.setCellValue("序号");
                cell.setCellStyle(style);
                CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(1,256*19);
                cell = row.createCell(1);
                cell.setCellValue("线路");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 1, 1);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(2,256*19);
                cell = row.createCell(2);
                cell.setCellValue("基站名称");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 2, 2);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(3,256*19*3);
                cell = row.createCell(3);
                cell.setCellValue("基站铁塔位置");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 3, 5);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(6,256*14);
                cell = row.createCell(6);
                cell.setCellValue("基站站型");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 6, 6);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(7,256*14);
                cell = row.createCell(7);
                cell.setCellValue("小区序号");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 7, 7);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(8,256*19);
                cell = row.createCell(8);
                cell.setCellValue("小区名称");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 8, 8);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(9,256*22);
                cell = row.createCell(9);
                cell.setCellValue("全球小区识别码(CGI)");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 9, 9);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(10,256*14);
                cell = row.createCell(10);
                cell.setCellValue("DA值");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 10, 10);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(11,256*19);
                cell = row.createCell(11);
                cell.setCellValue("路由区编码(RAC)");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 11, 11);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(12,256*22);
                cell = row.createCell(12);
                cell.setCellValue("基站识别色码(BSIC)");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 12, 12);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(13,256*14);
                cell = row.createCell(13);
                cell.setCellValue("载频数");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 13, 13);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(14,256*14);
                cell = row.createCell(14);
                cell.setCellValue("归属BSC");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 14, 14);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(15,256*14);
                cell = row.createCell(15);
                cell.setCellValue("基站组环");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 15, 15);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(16,256*14);
                cell = row.createCell(16);
                cell.setCellValue("车站名称");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 16, 16);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(17,256*14);
                cell = row.createCell(17);
                cell.setCellValue("备注");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 17, 17);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(18,256*14);
                cell = row.createCell(18);
                cell.setCellValue("制作要求");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 18, 18);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                headerrow++;

                HSSFRow  row2 = sheet.getRow(1);
                if(row2==null){
                    row2 = sheet.createRow(1);
                }
                sheet.setColumnWidth(3,256*19);
                cell = row2.createCell(3);
                cell.setCellValue("公里标");
                cell.setCellStyle(style);

                sheet.setColumnWidth(4,256*19);
                cell = row2.createCell(4);
                cell.setCellValue("经度");
                cell.setCellStyle(style);

                sheet.setColumnWidth(5,256*19);
                cell = row2.createCell(5);
                cell.setCellValue("纬度");
                cell.setCellStyle(style);
                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportTemplateDb2(String excelName, String sheetName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = 1;
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            HSSFRow  row = sheet.createRow(headerrow);
            //表头样式
            HSSFCellStyle style = wb.createCellStyle();
            HSSFFont font = wb.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            font.setFontName(excelfont);
            font.setFontHeightInPoints((short) 11);
            style.setFont(font);
            style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            style.setBorderRight(HSSFCellStyle.BORDER_THIN);
            style.setBorderTop(HSSFCellStyle.BORDER_THIN);

            sheet.setColumnWidth(0,256*14+256*19+256*14);
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("直放站");
            cell.setCellStyle(style);
            CellRangeAddress region = new CellRangeAddress(0, 0, 0, 2);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(3,256*14+256*19+256*14);
            cell = row.createCell(3);
            cell.setCellValue("近端机");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 3, 5);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(6,256*14+256*19+256*14+256*14);
            cell = row.createCell(6);
            cell.setCellValue("远端机");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 6, 9);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(10,256*14+256*19+256*14+256*14);
            cell = row.createCell(10);
            cell.setCellValue("铁塔");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 10, 13);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(14,256*14);
            cell = row.createCell(14);
            cell.setCellValue("备注");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 14, 14);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(15,256*14);
            cell = row.createCell(15);
            cell.setCellValue("制作要求");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 15, 15);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            HSSFRow  row2 = sheet.getRow(1);
            if(row2==null){
                row2 = sheet.createRow(1);
            }

            sheet.setColumnWidth(0,256*14);
            cell = row2.createCell(0);
            cell.setCellValue("序号");
            cell.setCellStyle(style);

            sheet.setColumnWidth(1,256*19);
            cell = row2.createCell(1);
            cell.setCellValue("施主基站名称");
            cell.setCellStyle(style);

            sheet.setColumnWidth(2,256*14);
            cell = row2.createCell(2);
            cell.setCellValue("漏缆(m)");
            cell.setCellStyle(style);

            sheet.setColumnWidth(3,256*14);
            cell = row2.createCell(3);
            cell.setCellValue("序号");
            cell.setCellStyle(style);

            sheet.setColumnWidth(4,256*19);
            cell = row2.createCell(4);
            cell.setCellValue("近端机名称");
            cell.setCellStyle(style);

            sheet.setColumnWidth(5,256*14);
            cell = row2.createCell(5);
            cell.setCellValue("公里标");
            cell.setCellStyle(style);

            sheet.setColumnWidth(6,256*14);
            cell = row2.createCell(6);
            cell.setCellValue("序号");
            cell.setCellStyle(style);

            sheet.setColumnWidth(7,256*19);
            cell = row2.createCell(7);
            cell.setCellValue("远端机名称");
            cell.setCellStyle(style);

            sheet.setColumnWidth(8,256*14);
            cell = row2.createCell(8);
            cell.setCellValue("公里标");
            cell.setCellStyle(style);

            sheet.setColumnWidth(9,256*14);
            cell = row2.createCell(9);
            cell.setCellValue("漏缆(m)");
            cell.setCellStyle(style);

            sheet.setColumnWidth(10,256*14);
            cell = row2.createCell(10);
            cell.setCellValue("序号");
            cell.setCellStyle(style);

            sheet.setColumnWidth(11,256*19);
            cell = row2.createCell(11);
            cell.setCellValue("公里标");
            cell.setCellStyle(style);

            sheet.setColumnWidth(12,256*14);
            cell = row2.createCell(12);
            cell.setCellValue("经度");
            cell.setCellStyle(style);

            sheet.setColumnWidth(13,256*14);
            cell = row2.createCell(13);
            cell.setCellValue("纬度");
            cell.setCellStyle(style);
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportDb2(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);

                sheet.setColumnWidth(0,256*14+256*19+256*14);
                HSSFCell cell = row.createCell(0);
                cell.setCellValue("直放站");
                cell.setCellStyle(style);
                CellRangeAddress region = new CellRangeAddress(0, 0, 0, 2);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(3,256*14+256*19+256*14);
                cell = row.createCell(3);
                cell.setCellValue("近端机");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 3, 5);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(6,256*14+256*19+256*14+256*14);
                cell = row.createCell(6);
                cell.setCellValue("远端机");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 6, 9);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(10,256*14+256*19+256*14+256*14);
                cell = row.createCell(10);
                cell.setCellValue("铁塔");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 10, 13);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(14,256*14);
                cell = row.createCell(14);
                cell.setCellValue("备注");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 14, 14);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(15,256*14);
                cell = row.createCell(15);
                cell.setCellValue("制作要求");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 15, 15);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(16,256*19);
                cell = row.createCell(16);
                cell.setCellValue("归属线路");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 16, 16);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                headerrow++;

                HSSFRow  row2 = sheet.getRow(1);
                if(row2==null){
                    row2 = sheet.createRow(1);
                }

                sheet.setColumnWidth(0,256*14);
                cell = row2.createCell(0);
                cell.setCellValue("序号");
                cell.setCellStyle(style);

                sheet.setColumnWidth(1,256*19);
                cell = row2.createCell(1);
                cell.setCellValue("施主基站名称");
                cell.setCellStyle(style);

                sheet.setColumnWidth(2,256*14);
                cell = row2.createCell(2);
                cell.setCellValue("漏缆(m)");
                cell.setCellStyle(style);

                sheet.setColumnWidth(3,256*14);
                cell = row2.createCell(3);
                cell.setCellValue("序号");
                cell.setCellStyle(style);

                sheet.setColumnWidth(4,256*19);
                cell = row2.createCell(4);
                cell.setCellValue("近端机名称");
                cell.setCellStyle(style);

                sheet.setColumnWidth(5,256*14);
                cell = row2.createCell(5);
                cell.setCellValue("公里标");
                cell.setCellStyle(style);

                sheet.setColumnWidth(6,256*14);
                cell = row2.createCell(6);
                cell.setCellValue("序号");
                cell.setCellStyle(style);

                sheet.setColumnWidth(7,256*19);
                cell = row2.createCell(7);
                cell.setCellValue("远端机名称");
                cell.setCellStyle(style);

                sheet.setColumnWidth(8,256*14);
                cell = row2.createCell(8);
                cell.setCellValue("公里标");
                cell.setCellStyle(style);

                sheet.setColumnWidth(9,256*14);
                cell = row2.createCell(9);
                cell.setCellValue("漏缆(m)");
                cell.setCellStyle(style);

                sheet.setColumnWidth(10,256*14);
                cell = row2.createCell(10);
                cell.setCellValue("序号");
                cell.setCellStyle(style);

                sheet.setColumnWidth(11,256*19);
                cell = row2.createCell(11);
                cell.setCellValue("公里标");
                cell.setCellStyle(style);

                sheet.setColumnWidth(12,256*14);
                cell = row2.createCell(12);
                cell.setCellValue("经度");
                cell.setCellStyle(style);

                sheet.setColumnWidth(13,256*14);
                cell = row2.createCell(13);
                cell.setCellValue("纬度");
                cell.setCellStyle(style);

                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportTemplateDb4(String excelName, String sheetName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = 1;
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            HSSFRow  row = sheet.createRow(headerrow);
            //表头样式
            HSSFCellStyle style = wb.createCellStyle();
            HSSFFont font = wb.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            font.setFontName(excelfont);
            font.setFontHeightInPoints((short) 11);
            style.setFont(font);
            style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            style.setBorderRight(HSSFCellStyle.BORDER_THIN);
            style.setBorderTop(HSSFCellStyle.BORDER_THIN);

            sheet.setColumnWidth(0,256*14);
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("序号");
            cell.setCellStyle(style);
            CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(1,256*19*2);
            cell = row.createCell(1);
            cell.setCellValue("本端设备");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 1, 2);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(3,256*19*2);
            cell = row.createCell(3);
            cell.setCellValue("对端设备");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 3, 4);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(5,256*19*3);
            cell = row.createCell(5);
            cell.setCellValue("互联链路");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 5, 7);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(8,256*19*3);
            cell = row.createCell(8);
            cell.setCellValue("业务/信令链路");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 8, 10);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(11,256*19);
            cell = row.createCell(11);
            cell.setCellValue("备注");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 11, 11);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(12,256*19);
            cell = row.createCell(12);
            cell.setCellValue("制作要求");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 12, 12);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            HSSFRow  row2 = sheet.getRow(1);
            if(row2==null){
                row2 = sheet.createRow(1);
            }

            sheet.setColumnWidth(1,256*19);
            cell = row2.createCell(1);
            cell.setCellValue("地点");
            cell.setCellStyle(style);

            sheet.setColumnWidth(2,256*19);
            cell = row2.createCell(2);
            cell.setCellValue("名称");
            cell.setCellStyle(style);

            sheet.setColumnWidth(3,256*19);
            cell = row2.createCell(3);
            cell.setCellValue("地点");
            cell.setCellStyle(style);

            sheet.setColumnWidth(4,256*19);
            cell = row2.createCell(4);
            cell.setCellValue("名称");
            cell.setCellStyle(style);

            sheet.setColumnWidth(5,256*19);
            cell = row2.createCell(5);
            cell.setCellValue("链路类型");
            cell.setCellStyle(style);

            sheet.setColumnWidth(6,256*19);
            cell = row2.createCell(6);
            cell.setCellValue("链路数量");
            cell.setCellStyle(style);

            sheet.setColumnWidth(7,256*19);
            cell = row2.createCell(7);
            cell.setCellValue("接口类型");
            cell.setCellStyle(style);

            sheet.setColumnWidth(8,256*19);
            cell = row2.createCell(8);
            cell.setCellValue("链路类型");
            cell.setCellStyle(style);

            sheet.setColumnWidth(9,256*19);
            cell = row2.createCell(9);
            cell.setCellValue("链路带宽");
            cell.setCellStyle(style);

            sheet.setColumnWidth(10,256*19);
            cell = row2.createCell(10);
            cell.setCellValue("链路数量");
            cell.setCellStyle(style);
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportDb4(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);

                sheet.setColumnWidth(0,256*14);
                HSSFCell cell = row.createCell(0);
                cell.setCellValue("序号");
                cell.setCellStyle(style);
                CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(1,256*19*2);
                cell = row.createCell(1);
                cell.setCellValue("本端设备");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 1, 2);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(3,256*19*2);
                cell = row.createCell(3);
                cell.setCellValue("对端设备");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 3, 4);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(5,256*19*3);
                cell = row.createCell(5);
                cell.setCellValue("互联链路");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 5, 7);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(8,256*19*3);
                cell = row.createCell(8);
                cell.setCellValue("业务/信令链路");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 8, 10);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(11,256*19);
                cell = row.createCell(11);
                cell.setCellValue("备注");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 11, 11);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(12,256*19);
                cell = row.createCell(12);
                cell.setCellValue("制作要求");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 12, 12);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(13,256*19);
                cell = row.createCell(13);
                cell.setCellValue("归属线路");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 13, 13);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                HSSFRow  row2 = sheet.getRow(1);
                if(row2==null){
                    row2 = sheet.createRow(1);
                }

                sheet.setColumnWidth(1,256*19);
                cell = row2.createCell(1);
                cell.setCellValue("地点");
                cell.setCellStyle(style);

                sheet.setColumnWidth(2,256*19);
                cell = row2.createCell(2);
                cell.setCellValue("名称");
                cell.setCellStyle(style);

                sheet.setColumnWidth(3,256*19);
                cell = row2.createCell(3);
                cell.setCellValue("地点");
                cell.setCellStyle(style);

                sheet.setColumnWidth(4,256*19);
                cell = row2.createCell(4);
                cell.setCellValue("名称");
                cell.setCellStyle(style);

                sheet.setColumnWidth(5,256*19);
                cell = row2.createCell(5);
                cell.setCellValue("链路类型");
                cell.setCellStyle(style);

                sheet.setColumnWidth(6,256*19);
                cell = row2.createCell(6);
                cell.setCellValue("链路数量");
                cell.setCellStyle(style);

                sheet.setColumnWidth(7,256*19);
                cell = row2.createCell(7);
                cell.setCellValue("接口类型");
                cell.setCellStyle(style);

                sheet.setColumnWidth(8,256*19);
                cell = row2.createCell(8);
                cell.setCellValue("链路类型");
                cell.setCellStyle(style);

                sheet.setColumnWidth(9,256*19);
                cell = row2.createCell(9);
                cell.setCellValue("链路带宽");
                cell.setCellStyle(style);

                sheet.setColumnWidth(10,256*19);
                cell = row2.createCell(10);
                cell.setCellValue("链路数量");
                cell.setCellStyle(style);

                headerrow++;

                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportTemplateDb6(String excelName, String sheetName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = 1;
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            HSSFRow  row = sheet.createRow(headerrow);
            //表头样式
            HSSFCellStyle style = wb.createCellStyle();
            HSSFFont font = wb.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            font.setFontName(excelfont);
            font.setFontHeightInPoints((short) 11);
            style.setFont(font);
            style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            style.setBorderRight(HSSFCellStyle.BORDER_THIN);
            style.setBorderTop(HSSFCellStyle.BORDER_THIN);

            sheet.setColumnWidth(0,256*14);
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("序号");
            cell.setCellStyle(style);
            CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(1,256*19+256*24);
            cell = row.createCell(1);
            cell.setCellValue("1240");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 1, 2);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(3,256*19+256*24);
            cell = row.createCell(3);
            cell.setCellValue("1340");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 3, 4);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(5,256*19);
            cell = row.createCell(5);
            cell.setCellValue("小区列表");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 5, 5);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(6,256*19);
            cell = row.createCell(6);
            cell.setCellValue("车站名称");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 6, 6);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            HSSFRow  row2 = sheet.getRow(1);
            if(row2==null){
                row2 = sheet.createRow(1);
            }

            sheet.setColumnWidth(1,256*24);
            cell = row2.createCell(1);
            cell.setCellValue("路由对象");
            cell.setCellStyle(style);

            sheet.setColumnWidth(2,256*19);
            cell = row2.createCell(2);
            cell.setCellValue("制作要求");
            cell.setCellStyle(style);

            sheet.setColumnWidth(3,256*24);
            cell = row2.createCell(3);
            cell.setCellValue("路由对象");
            cell.setCellStyle(style);

            sheet.setColumnWidth(4,256*19);
            cell = row2.createCell(4);
            cell.setCellValue("制作要求");
            cell.setCellStyle(style);
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportDb6(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);

                sheet.setColumnWidth(0,256*14);
                HSSFCell cell = row.createCell(0);
                cell.setCellValue("序号");
                cell.setCellStyle(style);
                CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(1,256*19+256*24);
                cell = row.createCell(1);
                cell.setCellValue("1240");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 1, 2);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(3,256*19+256*24);
                cell = row.createCell(3);
                cell.setCellValue("1340");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 3, 4);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(5,256*19);
                cell = row.createCell(5);
                cell.setCellValue("小区列表");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 5, 5);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(6,256*19);
                cell = row.createCell(6);
                cell.setCellValue("车站名称");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 6, 6);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(7,256*19);
                cell = row.createCell(7);
                cell.setCellValue("归属线路");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 7, 7);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                HSSFRow  row2 = sheet.getRow(1);
                if(row2==null){
                    row2 = sheet.createRow(1);
                }

                sheet.setColumnWidth(1,256*24);
                cell = row2.createCell(1);
                cell.setCellValue("路由对象");
                cell.setCellStyle(style);

                sheet.setColumnWidth(2,256*19);
                cell = row2.createCell(2);
                cell.setCellValue("制作要求");
                cell.setCellStyle(style);

                sheet.setColumnWidth(3,256*24);
                cell = row2.createCell(3);
                cell.setCellValue("路由对象");
                cell.setCellStyle(style);

                sheet.setColumnWidth(4,256*19);
                cell = row2.createCell(4);
                cell.setCellValue("制作要求");
                cell.setCellStyle(style);

                headerrow++;

                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportTemplateDb7(String excelName, String sheetName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = 1;
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            HSSFRow  row = sheet.createRow(headerrow);
            //表头样式
            HSSFCellStyle style = wb.createCellStyle();
            HSSFFont font = wb.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            font.setFontName(excelfont);
            font.setFontHeightInPoints((short) 11);
            style.setFont(font);
            style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            style.setBorderRight(HSSFCellStyle.BORDER_THIN);
            style.setBorderTop(HSSFCellStyle.BORDER_THIN);

            sheet.setColumnWidth(0,256*14);
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("序号");
            cell.setCellStyle(style);
            CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(1,256*24);
            cell = row.createCell(1);
            cell.setCellValue("车站名称");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 1, 1);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(2,256*29);
            cell = row.createCell(2);
            cell.setCellValue("车站基站区小区列表");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 2, 2);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(3,256*24);
            cell = row.createCell(3);
            cell.setCellValue("组ID(级别)");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 3, 3);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(4,256*29);
            cell = row.createCell(4);
            cell.setCellValue("组呼业务区编号(SA)");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 4, 4);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(5,256*19*2);
            cell = row.createCell(5);
            cell.setCellValue("组呼小区列表");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 5, 6);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(7,256*24*2);
            cell = row.createCell(7);
            cell.setCellValue("组呼人员列表");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 7, 8);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(9,256*19);
            cell = row.createCell(9);
            cell.setCellValue("备注");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 9, 9);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            HSSFRow  row2 = sheet.getRow(1);
            if(row2==null){
                row2 = sheet.createRow(1);
            }

            sheet.setColumnWidth(5,256*19);
            cell = row2.createCell(5);
            cell.setCellValue("组呼发起小区");
            cell.setCellStyle(style);

            sheet.setColumnWidth(6,256*19);
            cell = row2.createCell(6);
            cell.setCellValue("组呼接收小区");
            cell.setCellStyle(style);

            sheet.setColumnWidth(7,256*24);
            cell = row2.createCell(7);
            cell.setCellValue("组呼发起方");
            cell.setCellStyle(style);

            sheet.setColumnWidth(8,256*24);
            cell = row2.createCell(8);
            cell.setCellValue("组呼成员");
            cell.setCellStyle(style);
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportDb7(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);

                sheet.setColumnWidth(0,256*14);
                HSSFCell cell = row.createCell(0);
                cell.setCellValue("序号");
                cell.setCellStyle(style);
                CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(1,256*24);
                cell = row.createCell(1);
                cell.setCellValue("车站名称");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 1, 1);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(2,256*29);
                cell = row.createCell(2);
                cell.setCellValue("车站基站区小区列表");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 2, 2);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(3,256*24);
                cell = row.createCell(3);
                cell.setCellValue("组ID(级别)");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 3, 3);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(4,256*29);
                cell = row.createCell(4);
                cell.setCellValue("组呼业务区编号(SA)");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 4, 4);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(5,256*19*2);
                cell = row.createCell(5);
                cell.setCellValue("组呼小区列表");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 5, 6);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(7,256*24*2);
                cell = row.createCell(7);
                cell.setCellValue("组呼人员列表");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 7, 8);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(9,256*19);
                cell = row.createCell(9);
                cell.setCellValue("备注");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 9, 9);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(10,256*19);
                cell = row.createCell(10);
                cell.setCellValue("归属线路");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 10, 10);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                HSSFRow  row2 = sheet.getRow(1);
                if(row2==null){
                    row2 = sheet.createRow(1);
                }

                sheet.setColumnWidth(5,256*19);
                cell = row2.createCell(5);
                cell.setCellValue("组呼发起小区");
                cell.setCellStyle(style);

                sheet.setColumnWidth(6,256*19);
                cell = row2.createCell(6);
                cell.setCellValue("组呼接收小区");
                cell.setCellStyle(style);

                sheet.setColumnWidth(7,256*24);
                cell = row2.createCell(7);
                cell.setCellValue("组呼发起方");
                cell.setCellStyle(style);

                sheet.setColumnWidth(8,256*24);
                cell = row2.createCell(8);
                cell.setCellValue("组呼成员");
                cell.setCellStyle(style);

                headerrow++;

                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportTemplateDb8(String excelName, String sheetName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = 1;
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            HSSFRow  row = sheet.createRow(headerrow);
            //表头样式
            HSSFCellStyle style = wb.createCellStyle();
            HSSFFont font = wb.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            font.setFontName(excelfont);
            font.setFontHeightInPoints((short) 11);
            style.setFont(font);
            style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            style.setBorderRight(HSSFCellStyle.BORDER_THIN);
            style.setBorderTop(HSSFCellStyle.BORDER_THIN);

            sheet.setColumnWidth(0,256*14);
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("序号");
            cell.setCellStyle(style);
            CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(1,256*24);
            cell = row.createCell(1);
            cell.setCellValue("基准小区");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 1, 1);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(2,256*29);
            cell = row.createCell(2);
            cell.setCellValue("组ID及级别");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 2, 2);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(3,256*24);
            cell = row.createCell(3);
            cell.setCellValue("组呼业务区编号(SA)");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 3, 3);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(4,256*29);
            cell = row.createCell(4);
            cell.setCellValue("虚拟组呼号");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 4, 4);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(5,256*19*2);
            cell = row.createCell(5);
            cell.setCellValue("组呼小区列表");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 5, 6);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(7,256*24*2);
            cell = row.createCell(7);
            cell.setCellValue("组呼人员列表");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 7, 8);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(9,256*19);
            cell = row.createCell(9);
            cell.setCellValue("备注");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 9, 9);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            HSSFRow  row2 = sheet.getRow(1);
            if(row2==null){
                row2 = sheet.createRow(1);
            }

            sheet.setColumnWidth(5,256*19);
            cell = row2.createCell(5);
            cell.setCellValue("组呼发起小区");
            cell.setCellStyle(style);

            sheet.setColumnWidth(6,256*19);
            cell = row2.createCell(6);
            cell.setCellValue("组呼接收小区");
            cell.setCellStyle(style);

            sheet.setColumnWidth(7,256*24);
            cell = row2.createCell(7);
            cell.setCellValue("组呼发起方");
            cell.setCellStyle(style);

            sheet.setColumnWidth(8,256*24);
            cell = row2.createCell(8);
            cell.setCellValue("组呼成员");
            cell.setCellStyle(style);
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportDb8(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);

                sheet.setColumnWidth(0,256*14);
                HSSFCell cell = row.createCell(0);
                cell.setCellValue("序号");
                cell.setCellStyle(style);
                CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(1,256*24);
                cell = row.createCell(1);
                cell.setCellValue("基准小区");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 1, 1);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(2,256*29);
                cell = row.createCell(2);
                cell.setCellValue("组ID及级别");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 2, 2);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(3,256*24);
                cell = row.createCell(3);
                cell.setCellValue("组呼业务区编号(SA)");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 3, 3);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(4,256*29);
                cell = row.createCell(4);
                cell.setCellValue("虚拟组呼号");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 4, 4);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(5,256*19*2);
                cell = row.createCell(5);
                cell.setCellValue("组呼小区列表");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 5, 6);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(7,256*24*2);
                cell = row.createCell(7);
                cell.setCellValue("组呼人员列表");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 7, 8);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(9,256*19);
                cell = row.createCell(9);
                cell.setCellValue("备注");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 9, 9);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(10,256*19);
                cell = row.createCell(10);
                cell.setCellValue("归属线路");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 10, 10);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                HSSFRow  row2 = sheet.getRow(1);
                if(row2==null){
                    row2 = sheet.createRow(1);
                }

                sheet.setColumnWidth(5,256*19);
                cell = row2.createCell(5);
                cell.setCellValue("组呼发起小区");
                cell.setCellStyle(style);

                sheet.setColumnWidth(6,256*19);
                cell = row2.createCell(6);
                cell.setCellValue("组呼接收小区");
                cell.setCellStyle(style);

                sheet.setColumnWidth(7,256*24);
                cell = row2.createCell(7);
                cell.setCellValue("组呼发起方");
                cell.setCellStyle(style);

                sheet.setColumnWidth(8,256*24);
                cell = row2.createCell(8);
                cell.setCellValue("组呼成员");
                cell.setCellStyle(style);

                headerrow++;

                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportTemplateDb9(String excelName, String sheetName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = 1;
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            HSSFRow  row = sheet.createRow(headerrow);
            //表头样式
            HSSFCellStyle style = wb.createCellStyle();
            HSSFFont font = wb.createFont();
            font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            font.setFontName(excelfont);
            font.setFontHeightInPoints((short) 11);
            style.setFont(font);
            style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
            style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
            style.setBorderRight(HSSFCellStyle.BORDER_THIN);
            style.setBorderTop(HSSFCellStyle.BORDER_THIN);

            sheet.setColumnWidth(0,256*14);
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("序号");
            cell.setCellStyle(style);
            CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(1,256*19);
            cell = row.createCell(1);
            cell.setCellValue("小区名称");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 1, 1);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(2,256*29);
            cell = row.createCell(2);
            cell.setCellValue("全球小区识别码(CGI)");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 2, 2);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(3,256*19);
            cell = row.createCell(3);
            cell.setCellValue("归属GRIS");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 3, 3);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(4,256*19*3);
            cell = row.createCell(4);
            cell.setCellValue("CTC业务共基站数据");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 0, 4, 6);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(7,256*19);
            cell = row.createCell(7);
            cell.setCellValue("备注");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 7, 7);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            sheet.setColumnWidth(8,256*19);
            cell = row.createCell(8);
            cell.setCellValue("制作要求");
            cell.setCellStyle(style);
            region = new CellRangeAddress(0, 1, 8, 8);
            sheet.addMergedRegion(region);
            setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

            HSSFRow  row2 = sheet.getRow(1);
            if(row2==null){
                row2 = sheet.createRow(1);
            }

            sheet.setColumnWidth(4,256*19);
            cell = row2.createCell(4);
            cell.setCellValue("线路名称");
            cell.setCellStyle(style);

            sheet.setColumnWidth(5,256*19);
            cell = row2.createCell(5);
            cell.setCellValue("线路代码");
            cell.setCellStyle(style);

            sheet.setColumnWidth(6,256*19);
            cell = row2.createCell(6);
            cell.setCellValue("归属GRIS");
            cell.setCellStyle(style);
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportDb9(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);

                sheet.setColumnWidth(0,256*14);
                HSSFCell cell = row.createCell(0);
                cell.setCellValue("序号");
                cell.setCellStyle(style);
                CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(1,256*19);
                cell = row.createCell(1);
                cell.setCellValue("小区名称");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 1, 1);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(2,256*29);
                cell = row.createCell(2);
                cell.setCellValue("全球小区识别码(CGI)");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 2, 2);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(3,256*19);
                cell = row.createCell(3);
                cell.setCellValue("归属GRIS");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 3, 3);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(4,256*19*3);
                cell = row.createCell(4);
                cell.setCellValue("CTC业务共基站数据");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 4, 6);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(7,256*19);
                cell = row.createCell(7);
                cell.setCellValue("备注");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 7, 7);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(8,256*19);
                cell = row.createCell(8);
                cell.setCellValue("制作要求");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 8, 8);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(9,256*19);
                cell = row.createCell(9);
                cell.setCellValue("归属线路");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 9, 9);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                HSSFRow  row2 = sheet.getRow(1);
                if(row2==null){
                    row2 = sheet.createRow(1);
                }

                sheet.setColumnWidth(4,256*19);
                cell = row2.createCell(4);
                cell.setCellValue("线路名称");
                cell.setCellStyle(style);

                sheet.setColumnWidth(5,256*19);
                cell = row2.createCell(5);
                cell.setCellValue("线路代码");
                cell.setCellStyle(style);

                sheet.setColumnWidth(6,256*19);
                cell = row2.createCell(6);
                cell.setCellValue("归属GRIS");
                cell.setCellStyle(style);

                headerrow++;

                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportCellLevelStat(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);

                sheet.setColumnWidth(0,256*9);
                HSSFCell cell = row.createCell(0);
                cell.setCellValue("序号");
                cell.setCellStyle(style);
                CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(1,256*19);
                cell = row.createCell(1);
                cell.setCellValue("小区名称");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 1, 1);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(2,256*19*4);
                cell = row.createCell(2);
                cell.setCellValue("-60<=x<-10");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 2, 5);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(6,256*19*4);
                cell = row.createCell(6);
                cell.setCellValue("-70<=x<-60");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 6, 9);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(10,256*19*4);
                cell = row.createCell(10);
                cell.setCellValue("-80<=x<-70");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 10, 13);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(14,256*19*4);
                cell = row.createCell(14);
                cell.setCellValue("-92<=x<-80");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 14, 17);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(18,256*19*4);
                cell = row.createCell(18);
                cell.setCellValue("-120<=x<=-92");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 18, 21);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                HSSFRow  row2 = sheet.getRow(1);
                if(row2==null){
                    row2 = sheet.createRow(1);
                }

                sheet.setColumnWidth(2,256*19);
                cell = row2.createCell(2);
                cell.setCellValue("上行电平统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(3,256*19);
                cell = row2.createCell(3);
                cell.setCellValue("上行电平占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(4,256*19);
                cell = row2.createCell(4);
                cell.setCellValue("下行电平统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(5,256*19);
                cell = row2.createCell(5);
                cell.setCellValue("下行电平占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(6,256*19);
                cell = row2.createCell(6);
                cell.setCellValue("上行电平统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(7,256*19);
                cell = row2.createCell(7);
                cell.setCellValue("上行电平占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(8,256*19);
                cell = row2.createCell(8);
                cell.setCellValue("下行电平统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(9,256*19);
                cell = row2.createCell(9);
                cell.setCellValue("下行电平占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(10,256*19);
                cell = row2.createCell(10);
                cell.setCellValue("上行电平统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(11,256*19);
                cell = row2.createCell(11);
                cell.setCellValue("上行电平占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(12,256*19);
                cell = row2.createCell(12);
                cell.setCellValue("下行电平统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(13,256*19);
                cell = row2.createCell(13);
                cell.setCellValue("下行电平占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(14,256*19);
                cell = row2.createCell(14);
                cell.setCellValue("上行电平统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(15,256*19);
                cell = row2.createCell(15);
                cell.setCellValue("上行电平占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(16,256*19);
                cell = row2.createCell(16);
                cell.setCellValue("下行电平统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(17,256*19);
                cell = row2.createCell(17);
                cell.setCellValue("下行电平占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(18,256*19);
                cell = row2.createCell(18);
                cell.setCellValue("上行电平统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(19,256*19);
                cell = row2.createCell(19);
                cell.setCellValue("上行电平占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(20,256*19);
                cell = row2.createCell(20);
                cell.setCellValue("下行电平统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(21,256*19);
                cell = row2.createCell(21);
                cell.setCellValue("下行电平占比");
                cell.setCellStyle(style);

                headerrow++;

                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    public static void exportCellQualStat(String excelName, String sheetName,String[] headers,String[] ds_titles,int[] ds_format,int[] widths, List<Map<String,Object>> data ,HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        session.setAttribute("state", null);
        if(widths==null){
            widths = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                widths[i]=width;
            }
        }
        if(ds_format==null){
            ds_format = new int[ds_titles.length];
            for(int i=0;i<ds_titles.length;i++){
                ds_format[i]=1;
            }
        }
        //设置文件名
        String fileName = "";
        String dataFmt = DateTimeUtil.getNowDate("yyyyMMddHHmm");
        if(StringUtils.isNotEmpty(excelName)){
            fileName = excelName+"_"+dataFmt;
        }
        //创建一个工作薄
        HSSFWorkbook wb = new HSSFWorkbook();
        int sheetSize = (int)Math.ceil(new Double(data.size())/65535D);System.out.println("sheetSize:"+sheetSize);
        for(int s =1 ; s<=sheetSize; s++){
            //创建一个sheet
            HSSFSheet  sheet = wb.createSheet(StringUtils.isNotEmpty(sheetName)?sheetName+s:"excel");
            //创建表头，如果没有跳过
            int headerrow = 0;
            if(headers!=null){
                HSSFRow  row = sheet.createRow(headerrow);
                //表头样式
                HSSFCellStyle style = wb.createCellStyle();
                HSSFFont font = wb.createFont();
                font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                font.setFontName(excelfont);
                font.setFontHeightInPoints((short) 11);
                style.setFont(font);
                style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
                style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                style.setBorderTop(HSSFCellStyle.BORDER_THIN);

                sheet.setColumnWidth(0,256*9);
                HSSFCell cell = row.createCell(0);
                cell.setCellValue("序号");
                cell.setCellStyle(style);
                CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(1,256*19);
                cell = row.createCell(1);
                cell.setCellValue("小区名称");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 1, 1, 1);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(2,256*19*4);
                cell = row.createCell(2);
                cell.setCellValue("0级");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 2, 5);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(6,256*19*4);
                cell = row.createCell(6);
                cell.setCellValue("1级");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 6, 9);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(10,256*19*4);
                cell = row.createCell(10);
                cell.setCellValue("2级");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 10, 13);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(14,256*19*4);
                cell = row.createCell(14);
                cell.setCellValue("3级");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 14, 17);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(18,256*19*4);
                cell = row.createCell(18);
                cell.setCellValue("4级");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 18, 21);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(22,256*19*4);
                cell = row.createCell(22);
                cell.setCellValue("5级");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 22, 25);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(26,256*19*4);
                cell = row.createCell(26);
                cell.setCellValue("6级");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 26, 29);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                sheet.setColumnWidth(30,256*19*4);
                cell = row.createCell(30);
                cell.setCellValue("7级");
                cell.setCellStyle(style);
                region = new CellRangeAddress(0, 0, 30, 33);
                sheet.addMergedRegion(region);
                setBorderStyle(HSSFCellStyle.BORDER_THIN, region, sheet, wb);

                HSSFRow  row2 = sheet.getRow(1);
                if(row2==null){
                    row2 = sheet.createRow(1);
                }

                sheet.setColumnWidth(2,256*19);
                cell = row2.createCell(2);
                cell.setCellValue("上行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(3,256*19);
                cell = row2.createCell(3);
                cell.setCellValue("上行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(4,256*19);
                cell = row2.createCell(4);
                cell.setCellValue("下行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(5,256*19);
                cell = row2.createCell(5);
                cell.setCellValue("下行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(6,256*19);
                cell = row2.createCell(6);
                cell.setCellValue("上行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(7,256*19);
                cell = row2.createCell(7);
                cell.setCellValue("上行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(8,256*19);
                cell = row2.createCell(8);
                cell.setCellValue("下行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(9,256*19);
                cell = row2.createCell(9);
                cell.setCellValue("下行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(10,256*19);
                cell = row2.createCell(10);
                cell.setCellValue("上行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(11,256*19);
                cell = row2.createCell(11);
                cell.setCellValue("上行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(12,256*19);
                cell = row2.createCell(12);
                cell.setCellValue("下行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(13,256*19);
                cell = row2.createCell(13);
                cell.setCellValue("下行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(14,256*19);
                cell = row2.createCell(14);
                cell.setCellValue("上行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(15,256*19);
                cell = row2.createCell(15);
                cell.setCellValue("上行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(16,256*19);
                cell = row2.createCell(16);
                cell.setCellValue("下行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(17,256*19);
                cell = row2.createCell(17);
                cell.setCellValue("下行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(18,256*19);
                cell = row2.createCell(18);
                cell.setCellValue("上行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(19,256*19);
                cell = row2.createCell(19);
                cell.setCellValue("上行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(20,256*19);
                cell = row2.createCell(20);
                cell.setCellValue("下行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(21,256*19);
                cell = row2.createCell(21);
                cell.setCellValue("下行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(22,256*19);
                cell = row2.createCell(22);
                cell.setCellValue("上行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(23,256*19);
                cell = row2.createCell(23);
                cell.setCellValue("上行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(24,256*19);
                cell = row2.createCell(24);
                cell.setCellValue("下行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(25,256*19);
                cell = row2.createCell(25);
                cell.setCellValue("下行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(26,256*19);
                cell = row2.createCell(26);
                cell.setCellValue("上行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(27,256*19);
                cell = row2.createCell(27);
                cell.setCellValue("上行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(28,256*19);
                cell = row2.createCell(28);
                cell.setCellValue("下行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(29,256*19);
                cell = row2.createCell(29);
                cell.setCellValue("下行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(30,256*19);
                cell = row2.createCell(30);
                cell.setCellValue("上行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(31,256*19);
                cell = row2.createCell(31);
                cell.setCellValue("上行质量占比");
                cell.setCellStyle(style);

                sheet.setColumnWidth(32,256*19);
                cell = row2.createCell(32);
                cell.setCellValue("下行质量统计");
                cell.setCellStyle(style);

                sheet.setColumnWidth(33,256*19);
                cell = row2.createCell(33);
                cell.setCellValue("下行质量占比");
                cell.setCellStyle(style);

                headerrow++;

                headerrow++;
            }
            //表格主体  解析list
            if(data != null){
                List styleList = new ArrayList();

                for (int i = 0; i <ds_titles.length; i++) {  //列数
                    HSSFCellStyle style = wb.createCellStyle();
                    HSSFFont font = wb.createFont();
                    font.setFontName(excelfont);
                    font.setFontHeightInPoints((short) 10);
                    style.setFont(font);
                    style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
                    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
                    style.setBorderRight(HSSFCellStyle.BORDER_THIN);
                    style.setBorderTop(HSSFCellStyle.BORDER_THIN);
                    if(ds_format[i]==1){
                        style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
                    }else if(ds_format[i]==2){
                        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    }else if(ds_format[i]==3){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                    }else if(ds_format[i]==4){
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        //int类型
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
                    }else if(ds_format[i]==5){
                        //float类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));
                    }else if(ds_format[i]==6){
                        //百分比类型
                        style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
                        style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
                    }
                    styleList.add(style);
                }
                //        	if(data.size() > 65535){
                //        		data = data.subList(0, 65535);System.out.println("总记录数大于65535，鉴于excel的限制，只导出前65535条");
                //        	}
                int start = (s-1)*65535;
                int end = s*65535 > data.size() ? data.size() : s*65535;
                for (int i = start; i < end ; i++) {  //行数
                    HSSFRow  row = sheet.createRow(headerrow);
                    Map map = data.get(i);
                    for (int j = 0; j <ds_titles.length; j++) {  //列数
                        HSSFCell cell = row.createCell(j);
                        Object o = map.get(ds_titles[j]);
                        if(o==null||"".equals(o)){
                            cell.setCellValue("");
                        }else if(ds_format[j]==4){
                            //int
                            cell.setCellValue((Long.valueOf((map.get(ds_titles[j]))+"")).longValue());
                        }else if(ds_format[j]==5|| ds_format[j]==6){
                            //float
                            cell.setCellValue((Double.valueOf((map.get(ds_titles[j]))+"")).doubleValue());
                        }else {
                            cell.setCellValue(map.get(ds_titles[j])+"");
                        }

                        cell.setCellStyle((HSSFCellStyle)styleList.get(j));
                    }
                    headerrow++;
                }
            }
        }

        fileName=fileName+".xls";
        String filename = "";
        try{
            filename =encodeChineseDownloadFileName(request,fileName);
        }catch(Exception e){
            e.printStackTrace();
        }

        response.setHeader("Content-disposition", filename);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment;filename="+filename);
        response.setHeader("Pragma", "No-cache");
        OutputStream ouputStream = response.getOutputStream();
        wb.write(ouputStream);
        ouputStream.flush();
        ouputStream.close();
        session.setAttribute("state", "open");

    }

    //用poi自带的工具类来处理合并后的边框
    public static void setBorderStyle(int border,CellRangeAddress region,HSSFSheet sheet,HSSFWorkbook wb){
        RegionUtil.setBorderBottom(border,region, sheet, wb);
        RegionUtil.setBorderLeft(border,region, sheet, wb);
        RegionUtil.setBorderRight(border,region, sheet, wb);
        RegionUtil.setBorderTop(border,region, sheet, wb);
    }

    /**
     * 对文件流输出下载的中文文件名进行编码 屏蔽各种浏览器版本的差异性
     * @throws UnsupportedEncodingException
     */
    public static String encodeChineseDownloadFileName(
            HttpServletRequest request, String pFileName) throws Exception {

        String filename = null;
        String agent = request.getHeader("USER-AGENT");
        if (null != agent){
            if (-1 != agent.indexOf("Firefox")) {//Firefox
                filename = "=?UTF-8?B?" + (new String(org.apache.commons.codec.binary.Base64.encodeBase64(pFileName.getBytes("UTF-8"))))+ "?=";
            }else if (-1 != agent.indexOf("Chrome")) {//Chrome
                filename = new String(pFileName.getBytes(), "ISO8859-1");
            } else {//IE7+
                filename = java.net.URLEncoder.encode(pFileName, "UTF-8");
                filename = filename.replace("+", "%20");
            }
        } else {
            filename = pFileName;
        }
        return filename;
    }
}

